# Copyright (C) Kumo inc. and its affiliates.
# Author: Jeff.li lijippy@163.com
# All rights reserved.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https:#www.gnu.org/licenses/>.
#
# Build the test and build container for presto_cpp
#
FROM ghcr.io/facebookincubator/pollux-dev:centos9

ARG PRESTO_VERSION=0.290

ADD scripts /pollux/scripts/
RUN wget https://repo1.maven.org/maven2/com/facebook/presto/presto-server/${PRESTO_VERSION}/presto-server-${PRESTO_VERSION}.tar.gz
RUN wget https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/${PRESTO_VERSION}/presto-cli-${PRESTO_VERSION}-executable.jar

ARG PRESTO_PKG=presto-server-$PRESTO_VERSION.tar.gz
ARG PRESTO_CLI_JAR=presto-cli-$PRESTO_VERSION-executable.jar

ENV PRESTO_HOME="/opt/presto-server"
RUN cp $PRESTO_CLI_JAR /opt/presto-cli

RUN dnf install -y java-11-openjdk less procps python3 tzdata \
    && ln -s $(which python3) /usr/bin/python \
    && tar -zxf $PRESTO_PKG \
    && mv ./presto-server-$PRESTO_VERSION $PRESTO_HOME \
    && chmod +x /opt/presto-cli \
    && ln -s /opt/presto-cli /usr/local/bin/ \
    && mkdir -p $PRESTO_HOME/etc \
    && mkdir -p $PRESTO_HOME/etc/catalog \
    && mkdir -p $PRESTO_HOME/etc/data \
    && mkdir -p /usr/lib/presto/utils

# We set the timezone to America/Los_Angeles due to issue
# detailed here : https://github.com/facebookincubator/pollux/issues/8127
ENV TZ=America/Los_Angeles

COPY scripts/presto/etc/config.properties.example $PRESTO_HOME/etc/config.properties
COPY scripts/presto/etc/jvm.config.example $PRESTO_HOME/etc/jvm.config
COPY scripts/presto/etc/node.properties $PRESTO_HOME/etc/node.properties
COPY scripts/presto/etc/hive.properties $PRESTO_HOME/etc/catalog
COPY scripts/presto/start-prestojava.sh /opt

WORKDIR /pollux
